import "crvpuppet"

define at3_ldapclient($webaddr="", $roleid="") {
  if $AutoMode==true and $CloudCRV==true {
    $ldapuri=get_provider_attr($webaddr,$roleid,"uri")
    $ldapsuffix=get_provider_attr($webaddr,$roleid,"suffix")
  }
  
  if ( $AutoMode == false ) or ( $AutoMode==true and $CloudCRV==true ) {
    
    package { [ "openldap", "nss_ldap", "openldap-clients" ] :
      ensure => installed,
    }
    
    exec { "authconfig --ldapbasedn=\"$ldapsuffix\" --ldapserver=$ldapuri --enableldap --enableldapauth --update":
      require => Package[ "openldap", "nss_ldap", "openldap-clients" ],
    }
  }
  
  if $AutoMode==true and $CloudCRV==true {
    set_role_attr($webaddr,$roleid,"ProfileApplied","True")
  }
}

define at3_ldapclient_reverse($webaddr, $roleid) {
  set_role_attr($webaddr,$roleid,"ReverseProfileApplied","True")
}
